home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / dirmaster / dirmaster.dopus5 next >
Text File  |  1997-02-27  |  5KB  |  141 lines

  1. /*****************************************************************\
  2. *                                                                 *
  3. *  DIRTODEST and PARENTTODEST commands for Directory Opus 5       *
  4. *                                                                 *
  5. *  Written by Timo Kaikumaa (timok@cc.tut.fi)                     *
  6. *                                                                 *
  7. *  ARexx script for Directory Opus 5.5 giving you two new         *
  8. *  directory & lister commands. To make them work, place this     *
  9. *  script into "dopus5:modules" directory.                        *
  10. *                                                                 *
  11. *  This script was written because I wasn't happy with _any_      *
  12. *  command or script of this kind there was already available.    *
  13. *  (And there sure was loads of them.)                            *
  14. *                                                                 *
  15. *  Using these commands results in another lister with the        *
  16. *  same path (DirToDest) or the parent path of your current       *
  17. *  directory (ParentToDest) in it. However, the algorithm to      *
  18. *  determine the new lister is more complex than usually.         *
  19. *  When called without legal arguments, the state of the          *
  20. *  destination listers is first checked. If there is only one     *
  21. *  of them (and it's not the lister where this script was called  *
  22. *  from) it is the one to be used, then. However, if the command  *
  23. *  was used in the actual destination lister the same applies to  *
  24. *  the source listers as well. If these criterions are of no use, *
  25. *  a new check is performed. This time a pathless lister is being *
  26. *  looked for. Usually this means a lister showing the list of    *
  27. *  devices or current caches. If there are many of them, only the *
  28. *  first one is used. In case the search appears still            *
  29. *  unsuccessful, a new lister is finally opened.                  *
  30. *                                                                 *
  31. *  If there are selected directories in a lister where DirToDest  *
  32. *  is called from, the first of these is being used instead of    *
  33. *  current directory. This action also deselects the first        *
  34. *  directory entry.                                               *
  35. *                                                                 *
  36. *  Both commands can only be used within a lister context.        *
  37. *                                                                 *
  38. *  Parameters: NEW/S to always open a new lister.                 *
  39. *                                                                 *
  40. *  Bugs: perhaps customized too much to suit for anyone's taste.  *
  41. *                                                                 *
  42. *  Hint: the first lines of lister menu might be a good place     *
  43. *  for these commands.                                            *
  44. *                                                                 *
  45. \*****************************************************************/
  46.  
  47. /* $VER: dirmaster.dopus5 1.3 (27.2.97)
  48. */
  49.  
  50. parse arg portname function source dest arguments
  51. address value portname
  52. options results
  53.  
  54.  
  55. /* Initialization */
  56.  
  57. if function = 'init' then do
  58.   dopus command "DirToDest" program "dirmaster" desc "'Clones current directory'" template "'NEW/S'" source
  59.   dopus command "ParentToDest" program "dirmaster" desc "'Clones parent directory'" template "'NEW/S'" source
  60.   exit
  61.   end
  62.  
  63.  
  64. /* DirToDest */
  65.  
  66. if function = 'DirToDest' then do
  67.   if source = 0 then do
  68.     dopus request '"DirToDest cannot be used outside lister!"'
  69.     exit
  70.     end
  71.   lister query source path
  72.   mypath = RESULT
  73.   lister query source seldirs stem dirs
  74.   if dirs.count ~= 0 then do
  75.     mypath = mypath || dirs.0 || '/'
  76.     lister select source dirs.0 off
  77.     lister refresh source
  78.     end
  79.   call doit
  80.   end
  81.  
  82.  
  83. /* ParentToDest */
  84.  
  85. if function = 'ParentToDest' then do
  86.   if source = 0 then do
  87.     dopus request '"ParentToDest cannot be used outside lister!"'
  88.     exit
  89.     end
  90.   lister query source path
  91.   mypath = left(RESULT,max(lastpos(':',RESULT),(lastpos('/',strip(RESULT,'T','/')))))
  92.   call doit
  93.   end
  94.  
  95.  
  96. /* Common exit point */
  97.  
  98. exit
  99.  
  100.  
  101. /* Let's do it */
  102.  
  103. doit:
  104.  
  105.   if mypath = "" then return
  106.  
  107.   if arguments = "NEW" then do
  108.     lister new mypath
  109.     return
  110.     end
  111.  
  112.   lister query "dest" stem dests
  113.   if dests.count = 1 then do
  114.     if dests.0 ~= source then do
  115.       lister read dests.0 mypath
  116.       return
  117.       end
  118.     else do
  119.       lister query "source" stem dests
  120.       if dests.count = 1 then do
  121.         lister read dests.0 mypath
  122.         return
  123.         end
  124.       end
  125.     end
  126.  
  127.   lister query all stem dests
  128.   do i=0 for dests.count
  129.     if (source ~= dests.i) then do
  130.       lister query dests.i path
  131.       if RESULT = "" then do
  132.         lister read dests.i mypath
  133.         return
  134.         end
  135.       end
  136.     end
  137.  
  138.   lister new mypath
  139.  
  140.   return
  141.